<template>
  <div class="app-container">

    <el-table v-loading="loading" :data="caseList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="案例名称" align="center" prop="caseName" />
      <el-table-column label="问题类型" align="center" prop="qaTypeName" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleView(scope.row)"
          >查看</el-button>
          
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改咨询案例分析对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="90%" append-to-body>
      <p style="font-size: 24px;color:green">{{form.caseName}}</p>
      <code class="hljs" v-html="form.caseAnalysis"></code>	  
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listCase, getCase } from "@/api/consult/case";


export default {
  name: "Case",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 咨询案例分析表格数据
      caseList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        caseName: null,
        caseAnalysis: null,
      },
      // 表单参数
      form: {},
	  qaTypeId: '',
	  qaTypeList: [] , // 问题类型列表
      // 表单校验
      rules: {
        caseName: [
          { required: true, message: "案例名称不能为空", trigger: "blur" }
        ],
		qaTypeName: [
			{ required: true, message: "问题类型不能为空", trigger: "blur" }
		],
        caseAnalysis: [
          { required: true, message: "案例分析不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询咨询案例分析列表 */
    getList() {
      this.loading = true;
      listCase(this.queryParams).then(response => {
        this.caseList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
    },
    /** 查看操作 */
    handleView(row) {
      const caseId = row.caseId || this.ids
      getCase(caseId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "查看案例分析";
      });
    }
  }
};
</script>
